package com.grammer;

public class ThreadMainSubTest {
    private static boolean bShouldMain = false ;
    public static void main(String[] args){
        //new ThreadMainSubTest().init();
        int i = 0 ;
        for(i=0;i<5;i++){
            System.out.println(i);
        }
        --i;
        assert i ==5;
    }



    private class Business{
        boolean bShouldSub = true ;//相当于定义了控制改谁执行的信号灯
        public synchronized void mainThread(int i){
            if(bShouldSub){
                try{
                    this.wait();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                for(int j=0;j<5;j++){
                    System.out.println(Thread.currentThread().getName()+":i="+i+" ,j="+j);
                }
                bShouldSub = true ;
                this.notify();
            }
        }

        public synchronized void subThread(int i){
            if(!bShouldSub){
                try{
                    this.wait();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }

                for(int j=0;j<10;j++){
                    System.out.println(Thread.currentThread().getName()+":i="+i+",j="+j);
                }
                bShouldSub = false ;
                this.notify();
            }
        }
    }
}
